package cn.yx.framework.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BaseConstant {
    private static final Logger logger = LoggerFactory.getLogger(BaseConstant.class);
    private static BaseConstant sBaseConstant;
    private static String BASE_PACKAGE = "cn.com.yx.ms";
    static final String BASE_PACKAGE_PERSISTENCE_LAYER = BASE_PACKAGE + ".persistence";
    static final String BASE_PACKAGE_CACHE_LAYER = BASE_PACKAGE + ".service.impl";
    static final String LOCATIONS_MYBATIS_MAPPER;
    static final String BASE_PACKAGE_CONTROLLER_LAYER;
    static final String BASE_PACKAGE_DOMAIN_LAYER;
    private static final String CONFIG_KEY_DES_PREFIX = "osc.config.des";
    private static final String CONFIG_KEY_AES_PREFIX = "osc.config.aes";
    private static final String CONFIG_KEY_FILE_UPLOAD_PREFIX = "osc.config.upload";
    private static final String CONFIG_KEY_CACHE_PREFIX = "osc.config.cache";
    private static final String CONFIG_KEY_DOC_PREFIX = "osc.config.doc";
    private static final String CONFIG_KEY_FRAMEWORK_PREFIX = "osc.config.framework";
    private static final String CONFIG_KEY_FILTERS_CORS_PREFIX = "osc.config.filters.cros";
    public static final String CONTEXT_USER_PROFILE = "CONTEXT_USER_PROFILE_CLIENT";

    @Bean
    public BaseConstant.ApiDocConfig apiDocConfig() {
        return new BaseConstant.ApiDocConfig();
    }

    @Bean
    public BaseConstant.SignalRConfig signalRConfig() {
        return new BaseConstant.SignalRConfig();
    }

    @Bean
    public BaseConstant.BusApiConfig busApiConfig() {
        return new BaseConstant.BusApiConfig();
    }

    @Bean
    public BaseConstant.ServerConfig serverConfig() {
        return new BaseConstant.ServerConfig();
    }




//    @Bean
//    public BaseConstant.DesConfig desConfig() {
//        return new BaseConstant.DesConfig();
//    }

    @Bean
    public BaseConstant.UploadConfig uploadConfig() {
        return new BaseConstant.UploadConfig();
    }

    @Bean
    public BaseConstant.MyLogConfig myLogConfig() {
        return new BaseConstant.MyLogConfig();
    }

    @Bean
    public BaseConstant.AesConfig aesConfig() {
        return new BaseConstant.AesConfig();
    }

    //
    @Bean
    public BaseConstant.RedisCacheConfig redisCacheConfig() {
        return new BaseConstant.RedisCacheConfig();
    }
//
//    @Bean
//    public BaseConstant.FrameworkConfig frameworkConfig() {
//        return new BaseConstant.FrameworkConfig();
//    }
//
//    @Bean
//    public BaseConstant.CrosFilterConfig crosFilterConfig() {
//        return new BaseConstant.CrosFilterConfig();
//    }

    public BaseConstant() {
        sBaseConstant = this;
    }

    public static BaseConstant getInstance() {
        return sBaseConstant;
    }

    //    public static BaseConstant.DesConfig getDesConfig() {
//        return sBaseConstant.desConfig();
//    }
//
    public static BaseConstant.RedisCacheConfig getRedisCacheConfig() {
        return sBaseConstant.redisCacheConfig();
    }

    public static BaseConstant.AesConfig getAesConfig() {
        return sBaseConstant.aesConfig();
    }

    public static BaseConstant.UploadConfig getUploadConfig() {
        return sBaseConstant.uploadConfig();
    }

    public static BaseConstant.ApiDocConfig getApiDocConfig() {
        return sBaseConstant.apiDocConfig();
    }

    public static BaseConstant.MyLogConfig getMyLogConfig() {
        return sBaseConstant.myLogConfig();
    }

    public static BaseConstant.SignalRConfig getSignalRConfig() {
        return sBaseConstant.signalRConfig();
    }

    public static BaseConstant.BusApiConfig getBusApiConfig() {
        return sBaseConstant.busApiConfig();
    }

    public static BaseConstant.ServerConfig getServerConfig() {
        return sBaseConstant.serverConfig();
    }



//    public static BaseConstant.FrameworkConfig getFrameworkConfig() {
//        return sBaseConstant.frameworkConfig();
//    }
//
//    public static BaseConstant.CrosFilterConfig getCrosFilterConfig() {
//        return sBaseConstant.crosFilterConfig();
//    }

    static {
        LOCATIONS_MYBATIS_MAPPER = "classpath:".concat(BASE_PACKAGE.replaceAll("\\.", "/")).concat("/persistence/*.xml");
        BASE_PACKAGE_CONTROLLER_LAYER = String.format("%s.controller", new Object[]{BASE_PACKAGE});
        BASE_PACKAGE_DOMAIN_LAYER = String.format("%s.domain", new Object[]{BASE_PACKAGE});
    }

    @ConfigurationProperties(
            prefix = "osc.config.aes"
    )
    public static class AesConfig {
        private String vector;
        private String secretKey;

        public AesConfig() {
        }

        public String getVector() {
            return this.vector;
        }

        public void setVector(String vector) {
            this.vector = vector;
        }

        public String getSecretKey() {
            return this.secretKey;
        }

        public void setSecretKey(String secretKey) {
            this.secretKey = secretKey;
        }
    }

    //
//    @ConfigurationProperties(
//            prefix = "osc.config.des"
//    )
//    public static class DesConfig {
//        private String vector;
//        private String secretKey;
//
//        public DesConfig() {
//        }
//
//        public String getVector() {
//            return this.vector;
//        }
//
//        public void setVector(String vector) {
//            this.vector = vector;
//        }
//
//        public String getSecretKey() {
//            return this.secretKey;
//        }
//
//        public void setSecretKey(String secretKey) {
//            this.secretKey = secretKey;
//        }
//    }
//
//    @ConfigurationProperties(
//            prefix = "osc.config.upload"
//    )
//    public static class UploadConfig {
//        private long maxUploadSize = 5242880L;
//
//        public UploadConfig() {
//        }
//
//        public long getMaxUploadSize() {
//            return this.maxUploadSize;
//        }
//
//        public void setMaxUploadSize(long maxUploadSize) {
//            this.maxUploadSize = maxUploadSize;
//        }
//    }
//
//    @ConfigurationProperties(
//            prefix = "osc.config.filters.cros"
//    )
//    public static class CrosFilterConfig {
//        private String name = "crosFilter";
//        private int order;
//        private boolean enable;
//        private List<String> whiteList;
//        private int maxAge;
//        private String pattern;
//        private String allowMethods;
//        private boolean requiredCredential;
//
//        public CrosFilterConfig() {
//        }
//
//        public String getName() {
//            return this.name;
//        }
//
//        public void setName(String name) {
//            this.name = name;
//        }
//
//        public int getOrder() {
//            return this.order;
//        }
//
//        public void setOrder(int order) {
//            this.order = order;
//        }
//
//        public boolean isEnable() {
//            return this.enable;
//        }
//
//        public void setEnable(boolean enable) {
//            this.enable = enable;
//        }
//
//        public List<String> getWhiteList() {
//            return this.whiteList;
//        }
//
//        public void setWhiteList(List<String> whiteList) {
//            this.whiteList = whiteList;
//        }
//
//        public int getMaxAge() {
//            return this.maxAge;
//        }
//
//        public void setMaxAge(int maxAge) {
//            this.maxAge = maxAge;
//        }
//
//        public String getPattern() {
//            return this.pattern;
//        }
//
//        public void setPattern(String pattern) {
//            this.pattern = pattern;
//        }
//
//        public String getAllowMethods() {
//            return this.allowMethods;
//        }
//
//        public void setAllowMethods(String allowMethods) {
//            this.allowMethods = allowMethods;
//        }
//
//        public boolean isRequiredCredential() {
//            return this.requiredCredential;
//        }
//
//        public void setRequiredCredential(boolean requiredCredential) {
//            this.requiredCredential = requiredCredential;
//        }
//    }
//
//    @ConfigurationProperties(
//            prefix = "osc.config.framework"
//    )
//    public static class FrameworkConfig {
//        private String basePackage;
//
//        public FrameworkConfig() {
//        }
//
//        public String getBasePackage() {
//            return this.basePackage;
//        }
//
//        public void setBasePackage(String basePackage) {
//            this.basePackage = basePackage;
//        }
//    }
//
    @ConfigurationProperties(
            prefix = "osc.config.rediscache"
    )
    public static class RedisCacheConfig {
        private int overtime;

        public int getOvertime() {
            return overtime;
        }

        public void setOvertime(int overtime) {
            this.overtime = overtime;
        }
        //        private boolean loadRemoteCachesOnStartup = true;
//        private List<String> names;
//        private boolean transactionAware;

        public RedisCacheConfig() {
        }

    }

    @ConfigurationProperties(
            prefix = "osc.config.doc"
    )
    public static class ApiDocConfig {
        private String title;
        private String teamName;
        private String website;
        private String email;
        private String description;
        private String license;
        private String version;
        private String licenseUrl;
        private String serviceUrl;

        public ApiDocConfig() {
        }

        public String getTitle() {
            return this.title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getTeamName() {
            return this.teamName;
        }

        public void setTeamName(String teamName) {
            this.teamName = teamName;
        }

        public String getWebsite() {
            return this.website;
        }

        public void setWebsite(String website) {
            this.website = website;
        }

        public String getEmail() {
            return this.email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getDescription() {
            return this.description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getLicense() {
            return this.license;
        }

        public void setLicense(String license) {
            this.license = license;
        }

        public String getVersion() {
            return this.version;
        }

        public void setVersion(String version) {
            this.version = version;
        }

        public String getLicenseUrl() {
            return this.licenseUrl;
        }

        public void setLicenseUrl(String licenseUrl) {
            this.licenseUrl = licenseUrl;
        }

        public String getServiceUrl() {
            return this.serviceUrl;
        }

        public void setServiceUrl(String serviceUrl) {
            this.serviceUrl = serviceUrl;
        }
    }

    @ConfigurationProperties(
            prefix = "osc.config.upload"
    )
    public static class UploadConfig {
        private String filepath;
        private String requestfilepath;
        private String modeldatapath;

        public String getFilepath() {
            return filepath;
        }

        public void setFilepath(String filepath) {
            this.filepath = filepath;
        }

        public String getRequestfilepath() {
            return requestfilepath;
        }

        public void setRequestfilepath(String requestfilepath) {
            this.requestfilepath = requestfilepath;
        }

        public String getModeldatapath() {
            return modeldatapath;
        }

        public void setModeldatapath(String modeldatapath) {
            this.modeldatapath = modeldatapath;
        }

        public UploadConfig() {
        }


    }

    @ConfigurationProperties(
            prefix = "osc.config.mylog"
    )
    public static class MyLogConfig {
        private String logpath;

        public String getLogpath() {
            return logpath;
        }

        public void setLogpath(String logpath) {
            this.logpath = logpath;
        }
    }

    @ConfigurationProperties(
            prefix = "osc.config.signalr"
    )
    public static class SignalRConfig {
        private String address;
        private String hubname;

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getHubname() {
            return hubname;
        }

        public void setHubname(String hubname) {
            this.hubname = hubname;
        }
    }

    @ConfigurationProperties(prefix = "osc.config.busapi")
    public static class BusApiConfig{
        private String url;

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }

    @ConfigurationProperties(prefix = "osc.config.server")
    public static class ServerConfig{
        private String url;
        private String mediaurl;

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getMediaurl() {
            return mediaurl;
        }

        public void setMediaurl(String mediaurl) {
            this.mediaurl = mediaurl;
        }
    }




}
